"""
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    created by siyi.chen on '20/11/2024'
    comment: 卡片服务相关接口
"""
import asyncio

from config import Config
from project.model.micro_service import MicroService


class Vision:

    @staticmethod
    async def get_card_list(token):
        """ 获取卡片列表
        :param token: 卡片系统token
        :return:
        """
        data = await MicroService(domain=Config.VISION_DOMAIN, headers={'authorization': f'Bearer {token}'}).get(url_path='/api/section/list',
                                                                                                                 page=1, page_size=1000, publish_status=1, permission_type=2)
        return data

    @staticmethod
    async def get_card_list_with_org(organization_code):
        """ 获取卡片列表
        :param organization_code: 机构编码
        :return:
        """
        data = await MicroService(domain=Config.VISION_DOMAIN).get(url_path='/api/section/b/list', organization_code=organization_code, page=1, page_size=1000, publish_status=1, permission_type=2)
        return data

    @staticmethod
    async def get_cards_with_codes(token=None, organization_code=None, codes=None):
        """
        :param token:
        :param codes:
        :return:
        """
        cards = []
        if token:
            data = await Vision.get_card_list(token)
        elif organization_code:
            data = await Vision.get_card_list_with_org(organization_code)
        else:
            return cards
        for item in data.get('items'):
            if item.get('recognize_txt') not in codes:
                continue
            cards.append(item)

        return cards


if __name__ == '__main__':
    pass
    result = asyncio.run(Vision.get_cards_with_codes('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTczMDA4NTQ1MCwianRpIjoiMzNmMTdkM2ItMTFmZi00OWEzLTg4M2QtYzU2NjMzMzNmNjhmIiwidHlwZSI6ImFjY2VzcyIsInN1YiI6MzcsIm5iZiI6MTczMDA4NTQ1MCwiZXhwIjo0ODgzNjg1NDUwfQ.CROT50Z6egF5M4Gfw0zIkgR9VPU1fqKhoDH2eBKRDNI', 'XLDWA40000370001'))
    print(result)



